package com.xindaoapp.henghua.asset;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.xindaoapp.henghua.R;

public class LoadingDialog extends Dialog {
	private ImageView imageView;
	private int imageResource;

	public LoadingDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
	}

	public LoadingDialog(Context context, int theme) {
		super(context, theme);
	}

	public LoadingDialog(Context context) {
		super(context);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_downloading);
		imageView = (ImageView) findViewById(R.id.icon);
		imageView.setOnClickListener(mOnClickListener);
		imageView.setImageResource(imageResource);
	}

	private final View.OnClickListener mOnClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			if (imageResource == R.drawable.failed) {
				dismiss();
			}
		}
	};

	public void setImageView(int imageResource) {
		this.imageResource = imageResource;
//		imageView.setImageResource(imageResource);
	}
}
